/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package quanlykho;

import java.awt.Color;
import java.awt.Image;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.ComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Admin
 */

public class UpdateNV extends javax.swing.JPanel implements ListSelectionListener,KeyListener{

    /**
     * Creates new form UpdateNV
     */
static BufferedImage bufImg  =null ;
String str = null;
File file = null;
Image img=null;
ButtonGroup rd = new ButtonGroup();
ButtonGroup rd1 = new ButtonGroup();
String stranh=null;
String bophan=null;
String mabp=null;
boolean gioitinh =true; 
String manv=null;
static Vector t=null;
DefaultTableModel model;
    public UpdateNV(String st) {
        try {
            initComponents();
            tb1.addKeyListener(this);
            panh.setEnabled(true);
            rd.add(rb1);
            rd.add(rb2);
            rd1.add(rb3);
            rd1.add(rb4);
           rb1.setSelected(true); 
           bophan=st;
           Ketnoi a = new Ketnoi();
           Connection con = a.connect();
           
           loadTable(st);
           PreparedStatement pst = con.prepareCall("Select * from bophan where tenbp = ?");
           pst.setString(1, st);
           ResultSet rs = pst.executeQuery();
           while(rs.next())
                   {
                       mabp=rs.getString(1);
                   }
           String st1="bophan";
           
            loadCb(cb1, st1, 2);
            Vector t = new Vector();
            t = getCb(st1, 1);
            System.out.println(t.get(0).toString());
            model = (DefaultTableModel) jt1.getModel();
            jt1.getSelectionModel().addListSelectionListener(this);
            int number = jt1.getRowCount();
            if(number>=0)
            {
                jt1.setRowSelectionInterval(0, 0);
            }
        } catch (SQLException ex) {
            Logger.getLogger(UpdateNV.class.getName()).log(Level.SEVERE, null, ex);
        }
       an();
    }
        public void loadCb(JComboBox cb,String str,int index)
    {
        try {
            Ketnoi a = new Ketnoi();
            Connection con = a.connect();
            cb.removeAllItems();
            cb.addItem("Lựa chọn");
            String str1="Select * from "+str;
            System.out.println(str1);
            PreparedStatement pst = con.prepareCall(str1);
            ResultSet rs = pst.executeQuery();
            while(rs.next())
            {
                cb.addItem(rs.getString(index));  
            }
            
        } catch (SQLException ex) {
            Logger.getLogger(ThongTinHangHoa.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
            public Vector getCb(String str,int index)
    {
        Vector v = new Vector();
        try {
            Ketnoi a = new Ketnoi();
            Connection con = a.connect();
            String str1="Select * from "+str;
            PreparedStatement pst = con.prepareCall(str1);
           ResultSet rs = pst.executeQuery();
            while(rs.next())
            {
                v.add(rs.getString(index));  
            }
            String st = null;
        } catch (SQLException ex) {
            Logger.getLogger(ThongTinHangHoa.class.getName()).log(Level.SEVERE, null, ex);
        }
        return v;
    }
    public void xoa()
    {
        t1.setText("");
        t2.setText("");
        t3.setText("");
        t4.setText("");
        t5.setText("");
        t6.setText("");
        panh.setVisible(false);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jt1 = new javax.swing.JTable();
        jrb2 = new javax.swing.JRadioButton();
        jrb1 = new javax.swing.JRadioButton();
        jLabel9 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jtb3 = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jtb4 = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jtb2 = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        jtb1 = new javax.swing.JTextField();
        jp3 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jLabel10 = new javax.swing.JLabel();
        tb1 = new javax.swing.JTextField();
        l1 = new javax.swing.JLabel();
        tb2 = new javax.swing.JTextField();
        l2 = new javax.swing.JLabel();
        rb3 = new javax.swing.JRadioButton();
        rb4 = new javax.swing.JRadioButton();
        l3 = new javax.swing.JLabel();
        tb3 = new javax.swing.JTextField();
        l4 = new javax.swing.JLabel();
        tb4 = new javax.swing.JTextField();
        l5 = new javax.swing.JLabel();
        tb5 = new javax.swing.JTextField();
        l6 = new javax.swing.JLabel();
        tb6 = new javax.swing.JTextField();
        l7 = new javax.swing.JLabel();
        panh1 = new javax.swing.JPanel();
        b1 = new javax.swing.JButton();
        b2 = new javax.swing.JButton();
        b3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        l9 = new javax.swing.JLabel();
        cb1 = new javax.swing.JComboBox();
        jPanel3 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        t1 = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        t2 = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        rb1 = new javax.swing.JRadioButton();
        rb2 = new javax.swing.JRadioButton();
        jLabel4 = new javax.swing.JLabel();
        t3 = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        t4 = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        t5 = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        t6 = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        panh = new javax.swing.JPanel();
        jButton2 = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();

        jTabbedPane1.setBackground(new java.awt.Color(204, 204, 204));
        jTabbedPane1.setBorder(new javax.swing.border.MatteBorder(null));

        jt1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Mã NV", "Tên nhân viên", "Số điện thoại"
            }
        ));
        jScrollPane1.setViewportView(jt1);
        jt1.getColumnModel().getColumn(0).setPreferredWidth(50);
        jt1.getColumnModel().getColumn(1).setPreferredWidth(130);

        jrb2.setText("Nữ");

        jrb1.setText("Nam");

        jLabel9.setText("Giới tính");

        jLabel11.setText("Địa chỉ ");

        jLabel12.setText("Ngày sinh");

        jLabel13.setText("Chức vụ");

        jLabel14.setText("Bộ phân");

        javax.swing.GroupLayout jp3Layout = new javax.swing.GroupLayout(jp3);
        jp3.setLayout(jp3Layout);
        jp3Layout.setHorizontalGroup(
            jp3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 201, Short.MAX_VALUE)
        );
        jp3Layout.setVerticalGroup(
            jp3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 171, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 403, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jrb1, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jrb2)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jtb3, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(2, 2, 2))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel14, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jtb1, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jtb4, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jtb2, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jp3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                        .addGap(149, 149, 149)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jtb3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel9)
                        .addComponent(jrb1)
                        .addComponent(jrb2)
                        .addComponent(jLabel11)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtb4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12)
                    .addComponent(jtb1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel14))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jtb2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel13))
                    .addComponent(jp3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(54, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Thông Tin Chung", jPanel1);

        jLabel10.setText("Mã nhân viên");

        l1.setText("Tên nhân viên");

        l2.setText("Giới tính");

        rb3.setText("Nam");

        rb4.setText("Nữ");

        l3.setText("Ngày sinh");

        l4.setText("Địa chỉ");

        l5.setText("Số điện thoại");

        l6.setText("Chức vụ");

        l7.setText("Ảnh");

        panh1.setBorder(new javax.swing.border.MatteBorder(null));

        javax.swing.GroupLayout panh1Layout = new javax.swing.GroupLayout(panh1);
        panh1.setLayout(panh1Layout);
        panh1Layout.setHorizontalGroup(
            panh1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 204, Short.MAX_VALUE)
        );
        panh1Layout.setVerticalGroup(
            panh1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 149, Short.MAX_VALUE)
        );

        b1.setText("Chọn ảnh");
        b1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b1ActionPerformed(evt);
            }
        });

        b2.setText("Sửa");
        b2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b2ActionPerformed(evt);
            }
        });

        b3.setText("Nhập lại");
        b3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b3ActionPerformed(evt);
            }
        });

        jButton4.setText("Tìm kiếm");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        l9.setText("Bộ phận");

        cb1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cb1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(l4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(l3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(l2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(l1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 75, Short.MAX_VALUE)
                                    .addComponent(jLabel10, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                                            .addComponent(rb3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addGap(18, 18, 18)
                                            .addComponent(rb4, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addComponent(tb2, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(tb1, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(tb3, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(tb4, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(l9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(l5, javax.swing.GroupLayout.DEFAULT_SIZE, 75, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(tb5, javax.swing.GroupLayout.DEFAULT_SIZE, 124, Short.MAX_VALUE)
                                    .addComponent(cb1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(b2, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(40, 40, 40)))
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(b3, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(panh1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(l7, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(l6, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(tb6, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(b1, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jButton4))
                .addContainerGap(97, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(tb1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton4))
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(l1)
                    .addComponent(tb2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tb6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(l6))
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(l2)
                    .addComponent(rb3)
                    .addComponent(rb4)
                    .addComponent(l7)
                    .addComponent(b1))
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(l3)
                            .addComponent(tb3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(28, 28, 28)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(l4)
                            .addComponent(tb4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(tb5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(l5))
                        .addGap(25, 25, 25)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(l9)
                            .addComponent(cb1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(panh1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(31, 31, 31)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(b3)
                    .addComponent(b2))
                .addContainerGap(55, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(27, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Sửa Nhân Viên", jPanel2);

        jLabel1.setText("Mã nhân viên");

        jLabel2.setText("Tên nhân viên");

        jLabel3.setText("Giới tính");

        rb1.setText("Nam");

        rb2.setText("Nữ");

        jLabel4.setText("Ngày sinh");

        jLabel5.setText("Địa chỉ");

        jLabel6.setText("Số điện thoại");

        jLabel7.setText("Chức vụ");

        jLabel8.setText("Ảnh");

        panh.setBorder(new javax.swing.border.MatteBorder(null));

        javax.swing.GroupLayout panhLayout = new javax.swing.GroupLayout(panh);
        panh.setLayout(panhLayout);
        panhLayout.setHorizontalGroup(
            panhLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 204, Short.MAX_VALUE)
        );
        panhLayout.setVerticalGroup(
            panhLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 155, Short.MAX_VALUE)
        );

        jButton2.setText("Chọn ảnh");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton1.setText("Thêm");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton3.setText("Nhập lại");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 75, Short.MAX_VALUE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                                .addComponent(rb1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGap(18, 18, 18)
                                .addComponent(rb2, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(t2, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(t1, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, 50, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 152, Short.MAX_VALUE)
                            .addComponent(t6)))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(t3, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(t4, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(t5, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(panh, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 104, Short.MAX_VALUE)))))
                .addContainerGap(52, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(t1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7)
                    .addComponent(t6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(t2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8)
                    .addComponent(jButton2))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(rb1)
                            .addComponent(rb2))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(t3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(28, 28, 28)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(t4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(28, 28, 28)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(t5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(panh, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(33, 33, 33)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton3))
                .addContainerGap(126, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Thêm Nhân Viên", jPanel3);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 502, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(65, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 459, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
       panh.setVisible(true);
        JFileChooser fchooser = new JFileChooser("C:\\");
        //chi mo thu muc
       fchooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        
        
        if(fchooser.showOpenDialog(this)==JFileChooser.APPROVE_OPTION)
        {
            try {
                //lay duong dan thu muc da chon
                String path = fchooser.getCurrentDirectory().getPath().toString();
                File selected = fchooser.getSelectedFile();
                String str=selected.getPath();
                boolean flag = false;
                //tao doi tuong File
                File f = new File(str);
                System.out.println(str);
                Vector a = new Vector();
                if(f.getName().endsWith("jpg")||f.getName().endsWith("JPG") ||f.getName().endsWith("BPM") ||f.getName().endsWith("bmp"))
                {
                    stranh=str;
                    flag = true;  
                    a.add(f.getName());  
                }
                if(flag==false)
                {
                    stranh=null;
                    JOptionPane.showMessageDialog(this, "Bạn chọn sai file ảnh");
                }
                        panh.removeAll();
                        file = new File(str);
                        bufImg=ImageIO.read(file);
                        paint1 b = new paint1(bufImg);
                        
                        b.setSize(200, 200);
                        b.setLocation(0, 0);
                        b.setVisible(true);
                        b.setBorder(BorderFactory.createLineBorder(Color.red));
                        panh.add(b);
                        panh.updateUI();
                        panh.setVisible(true);
                       
                
                
                //lay danh sach cac file trong thu muc
    //            File[] files = f.listFiles();
    //            
    //            //tao doi tuong Vector
    //            Vector a = new Vector();
    //            
    //            //lay ten cac file trong thu muc add vao 1 vector
    //            for( File obj : files)
    //                //chi lay cac file anh co duoi la danh JPG
    //                if(obj.getName().endsWith("jpg")||obj.getName().endsWith("JPG")) 
    //                {
    //                    //them ten file anh vao vector
    //                    a.add(obj.getName());
    //                  //  System.out.println(obj.getName());
    //                }
    //            
                //gan danh sach ten cac file anh vao Jlist
            } catch (IOException ex) {
                Logger.getLogger(UpdateNV.class.getName()).log(Level.SEVERE, null, ex);
            }
            
} 
       
        
    }//GEN-LAST:event_jButton2ActionPerformed

    public void chonanh()
    {
         panh1.setVisible(true);
        JFileChooser fchooser = new JFileChooser("D:\\");
        //chi mo thu muc
       fchooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        
        
        if(fchooser.showOpenDialog(this)==JFileChooser.APPROVE_OPTION)
        {
            try {
                //lay duong dan thu muc da chon
                String path = fchooser.getCurrentDirectory().getPath().toString();
                File selected = fchooser.getSelectedFile();
                String str=selected.getPath();
                boolean flag = false;
                //tao doi tuong File
                File f = new File(str);
                System.out.println(str);
                Vector a = new Vector();
                if(f.getName().endsWith("jpg")||f.getName().endsWith("JPG") ||f.getName().endsWith("BPM") ||f.getName().endsWith("bmp"))
                {
                    stranh=str;
                    flag = true;  
                    a.add(f.getName());  
                }
                if(flag==false)
                {
                    stranh=null;
                    JOptionPane.showMessageDialog(this, "Bạn chọn sai file ảnh");
                }
                        panh1.removeAll();
                        file = new File(str);
                        bufImg=ImageIO.read(file);
                        paint1 b = new paint1(bufImg);
                        
                        b.setSize(200, 200);
                        b.setLocation(0, 0);
                        b.setVisible(true);
                        b.setBorder(BorderFactory.createLineBorder(Color.red));
                        panh1.add(b);
                        panh1.updateUI();
                        panh1.setVisible(true);
                       
                
                
                //lay danh sach cac file trong thu muc
    //            File[] files = f.listFiles();
    //            
    //            //tao doi tuong Vector
    //            Vector a = new Vector();
    //            
    //            //lay ten cac file trong thu muc add vao 1 vector
    //            for( File obj : files)
    //                //chi lay cac file anh co duoi la danh JPG
    //                if(obj.getName().endsWith("jpg")||obj.getName().endsWith("JPG")) 
    //                {
    //                    //them ten file anh vao vector
    //                    a.add(obj.getName());
    //                  //  System.out.println(obj.getName());
    //                }
    //            
                //gan danh sach ten cac file anh vao Jlist
            } catch (IOException ex) {
                Logger.getLogger(UpdateNV.class.getName()).log(Level.SEVERE, null, ex);
            }
            
} 
    }
    public void loadAnh(JPanel p,String str)
    {
        try {
             p.setVisible(true);
            BufferedImage buf  =null ;
            p.removeAll();
                            File f = new File(str);
                            buf=ImageIO.read(f);
                            paint1 b = new paint1(buf);
                            
                            b.setSize(200, 200);
                            b.setLocation(0, 0);
                            b.setVisible(true);
                            b.setBorder(BorderFactory.createLineBorder(Color.red));
                            p.add(b);
                            p.updateUI();
                            p.setVisible(true);
        } catch (IOException ex) {
            Logger.getLogger(UpdateNV.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
        public void loadTable(String str)
    {
        try {
            model = (DefaultTableModel) jt1.getModel();
                int num=jt1.getRowCount();
                for (int i = num-1; i >= 0; i--) {
                    model.removeRow(i);
                }
                Ketnoi a = new Ketnoi();
                Connection con = a.connect();
                PreparedStatement pst1 = con.prepareCall("Select * from bophan where tenbp = ?");
                pst1.setString(1, str);
                ResultSet rs1= pst1.executeQuery();
                String str1= null;
                while(rs1.next())
                {
                    str1=rs1.getString(1);
                }
                System.out.println(str1);
                PreparedStatement pst = con.prepareCall("Select * from nhanvien where mabp = ?");
                pst.setString(1, str1);
                ResultSet rs = pst.executeQuery();
                Vector b = null;
                while(rs.next())
                {
                    b=new Vector();
                    b.add(rs.getString(1));
                    b.add(rs.getString(2));
                    b.add(rs.getString(6));
                    model.addRow(b);
                }
        } catch (SQLException ex) {
            Logger.getLogger(ThongTinHangHoa.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
        xoa();
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        try {
            // TODO add your handling code here:
           boolean flag = true ;
           if(rb1.isSelected())
           {
               gioitinh=true;
           }
           if(rb2.isSelected())
           {
               gioitinh=false;
           }
            System.out.println(gioitinh);
           if(t1.getText().length()==0)
           {
               JOptionPane.showMessageDialog(this, "Vui lòng nhập vào mã nhân viên");
               t1.requestFocus();
               flag=false;
           }
           if(t2.getText().length()==0 && t1.getText().length()!=0)
           {
               JOptionPane.showMessageDialog(this, "Hãy nhập vào tên nhân viên");
               t2.requestFocus();
               flag=false;
           }
           if( t3.getText().length()==0 && t2.getText().length()!=0 && t1.getText().length()!=0)
           {
               JOptionPane.showMessageDialog(this, "Hãy nhập vào ngày sinh");
               t3.requestFocus();
               flag=false;
           }
           if( t4.getText().length()==0 && t3.getText().length()!=0 && t2.getText().length()!=0 && t1.getText().length()!=0)
           {
               JOptionPane.showMessageDialog(this, "Hãy nhập vào địa chỉ");
               t4.requestFocus();
               flag=false;
           }
           if( t5.getText().length()==0 && t4.getText().length()!=0 && t3.getText().length()!=0 && t2.getText().length()!=0 && t1.getText().length()!=0)
           {
               JOptionPane.showMessageDialog(this, "Hãy nhập vào số điện thoại");
               t5.requestFocus();
               flag=false;
           }
           if( t6.getText().length()==0 && t5.getText().length()!=0 && t4.getText().length()!=0 && t3.getText().length()!=0 && t2.getText().length()!=0 && t1.getText().length()!=0)
           {
               JOptionPane.showMessageDialog(this, "Hãy nhập vào chức vụ");
               t6.requestFocus();
               flag=false;
           }
           int test=0;
           Ketnoi a = new Ketnoi();
           Connection con = a.connect();
           PreparedStatement pst = con.prepareCall("Select * from nhanvien where manv =?");
           pst.setString(1, t1.getText());
           ResultSet rs = pst.executeQuery();
           while(rs.next())
           {
               test++;
           }
            System.out.println(test);
           if( test==1 && t6.getText().length()!=0 && t5.getText().length()!=0 && t4.getText().length()!=0 && t3.getText().length()!=0 && t2.getText().length()!=0 && t1.getText().length()!=0)
           {
               JOptionPane.showMessageDialog(this, "Mã nhân viên đã tồn tại");
               t1.requestFocus();
               flag=false;
           }
           if(flag!=false)
           {
               PreparedStatement pst1= con.prepareCall("Insert into nhanvien values(?,?,?,?,?,?,?,?,?)");
               pst1.setString(1, t1.getText());
               pst1.setString(2, t2.getText());
               pst1.setBoolean(3, gioitinh);
               pst1.setString(4, t3.getText());
               pst1.setString(5, t4.getText());
               pst1.setString(6, t5.getText());
               pst1.setString(7, t6.getText());
               pst1.setString(8, mabp);
               pst1.setString(9, stranh);
               pst1.executeUpdate();
           }    
        } catch (SQLException ex) {
            Logger.getLogger(UpdateNV.class.getName()).log(Level.SEVERE, null, ex);
        }
       
       
    }//GEN-LAST:event_jButton1ActionPerformed

    private void b1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b1ActionPerformed
        // TODO add your handling code here:
        chonanh();
    }//GEN-LAST:event_b1ActionPerformed
    
    private void b2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b2ActionPerformed
        // TODO add your handling code here:
                try {
            // TODO add your handling code here:
           boolean flag = true ;
           if(rb3.isSelected())
           {
               gioitinh=true;
           }
           if(rb4.isSelected())
           {
               gioitinh=false;
           }
                    System.out.println(gioitinh);
           if(tb1.getText().length()==0)
           {
               JOptionPane.showMessageDialog(this, "Vui lòng nhập vào mã nhân viên");
               tb1.requestFocus();
               flag=false;
           }
           if(tb2.getText().length()==0 && tb1.getText().length()!=0)
           {
               JOptionPane.showMessageDialog(this, "Hãy nhập vào tên nhân viên");
               tb2.requestFocus();
               flag=false;
           }
           if( tb3.getText().length()==0 && tb2.getText().length()!=0 && tb1.getText().length()!=0)
           {
               JOptionPane.showMessageDialog(this, "Hãy nhập vào ngày sinh");
               tb3.requestFocus();
               flag=false;
           }
           if( tb4.getText().length()==0 && tb3.getText().length()!=0 && tb2.getText().length()!=0 && tb1.getText().length()!=0)
           {
               JOptionPane.showMessageDialog(this, "Hãy nhập vào địa chỉ");
               tb4.requestFocus();
               flag=false;
           }
           if( tb5.getText().length()==0 && tb4.getText().length()!=0 && tb3.getText().length()!=0 && tb2.getText().length()!=0 && tb1.getText().length()!=0)
           {
               JOptionPane.showMessageDialog(this, "Hãy nhập vào số điện thoại");
               tb5.requestFocus();
               flag=false;
           }
           if( tb6.getText().length()==0 && tb5.getText().length()!=0 && tb4.getText().length()!=0 && tb3.getText().length()!=0 && tb2.getText().length()!=0 && tb1.getText().length()!=0)
           {
               JOptionPane.showMessageDialog(this, "Hãy nhập vào chức vụ");
               tb6.requestFocus();
               flag=false;
           }
           int test=0;
           Ketnoi a = new Ketnoi();
           Connection con = a.connect();
                    System.out.println(manv);
           if(manv.toUpperCase().equals(tb1.getText().toUpperCase())==false)
           {
           PreparedStatement pst = con.prepareCall("Select * from nhanvien where manv =?");
           pst.setString(1, tb1.getText());
           ResultSet rs = pst.executeQuery();
           while(rs.next())
           {
               test++;
           }
            System.out.println(test);
           if( test==1 && tb6.getText().length()!=0 && tb5.getText().length()!=0 && tb4.getText().length()!=0 && tb3.getText().length()!=0 && tb2.getText().length()!=0 && tb1.getText().length()!=0)
           {
               JOptionPane.showMessageDialog(this, "Mã nhân viên đã tồn tại");
               tb1.requestFocus();
               flag=false;
           }
               System.out.println(manv+t1.getText());
           }
           
                    System.out.println(gioitinh);
           int j= cb1.getSelectedIndex();
           if(j==0)
           {
               JOptionPane.showMessageDialog(this, "Chưa chọn bộ phận");
               cb1.requestFocus();
               flag=false;
           }
           if(flag!=false && j>0)
           {
               String st1="bophan";
               Vector t = new Vector();
                t = getCb(st1, 1);
               System.out.println(j);
               String st2=t.get(j-1).toString();
               //System.out.println(st2);
              //System.out.println(t.get(0).toString());
              // t.get(j).toString();
               PreparedStatement pst1= con.prepareCall("Update nhanvien set manv=?,tennv=?,gt=?,ns=?,diachi=?,sodt=?,chucvu=?,mabp=?,anh=? where manv=?");
               pst1.setString(1, tb1.getText());
               pst1.setString(2, tb2.getText());
               pst1.setBoolean(3, gioitinh);
               pst1.setString(4, tb3.getText());
               pst1.setString(5, tb4.getText());
               pst1.setString(6, tb5.getText());
               pst1.setString(7, tb6.getText());
               pst1.setString(8, st2);
               pst1.setString(9, stranh);
               pst1.setString(10, manv);
               pst1.executeUpdate();
               an();
           }    
        } catch (SQLException ex) {
            Logger.getLogger(UpdateNV.class.getName()).log(Level.SEVERE, null, ex);
        }
       
    }//GEN-LAST:event_b2ActionPerformed

    private void b3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b3ActionPerformed
        // TODO add your handling code here:
        an();
    }//GEN-LAST:event_b3ActionPerformed
    public void timkiem()
    {
        try {
            // TODO add your handling code here:
            Ketnoi a = new Ketnoi();
            int kiemtra=0;
            Connection con = a.connect();
            PreparedStatement pst = con.prepareCall("Select * from nhanvien where manv=?");
            pst.setString(1, tb1.getText());
            ResultSet rs = pst.executeQuery();
            
            while(rs.next())
            {
                kiemtra++;
                tb1.setText(rs.getString(1));
                tb2.setText(rs.getString(2));
                tb3.setText(rs.getString(4));
                tb4.setText(rs.getString(5));
                tb5.setText(rs.getString(6));
                tb6.setText(rs.getString(7));
                gioitinh=rs.getBoolean(3);
                stranh=rs.getString(9);
                manv=tb1.getText();
                System.out.println(manv);
            }
            if(gioitinh==true)
            {
                rb3.setSelected(gioitinh);
            }
            
            if(gioitinh==false)
            {
                rb4.setSelected(gioitinh);
            }
            if(kiemtra>0)
            {
                
            hien();
            panh1.removeAll();
            if(stranh!=null)
            {
                System.out.println(stranh);
                        file = new File(stranh);
                        bufImg=ImageIO.read(file);
                        paint1 b = new paint1(bufImg);
                        
                        b.setSize(200, 200);
                        b.setLocation(0, 0);
                        b.setVisible(true);
                        b.setBorder(BorderFactory.createLineBorder(Color.red));
                        panh1.add(b);
                        panh1.updateUI();
                        panh1.setVisible(true);
            }
            }
            if(stranh==null)
            {
                stranh="D:\\Anh\\1.jpg";
                file = new File(stranh);
                        bufImg=ImageIO.read(file);
                        paint1 b = new paint1(bufImg);
                        
                        b.setSize(200, 200);
                        b.setLocation(0, 0);
                        b.setVisible(true);
                        b.setBorder(BorderFactory.createLineBorder(Color.red));
                        panh1.add(b);
                        panh1.updateUI();
                        panh1.setVisible(true);
            }
            if(kiemtra==0)
            {
                JOptionPane.showMessageDialog(this, "Mã nhân viên không tồn tại vui lòng kiểm tra lại.");
            }
        } catch (IOException ex) {
            Logger.getLogger(UpdateNV.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(UpdateNV.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        try {
            // TODO add your handling code here:
            Ketnoi a = new Ketnoi();
            int kiemtra=0;
            Connection con = a.connect();
            PreparedStatement pst = con.prepareCall("Select * from nhanvien where manv=?");
            pst.setString(1, tb1.getText());
            ResultSet rs = pst.executeQuery();
            
            while(rs.next())
            {
                kiemtra++;
                tb1.setText(rs.getString(1));
                tb2.setText(rs.getString(2));
                tb3.setText(rs.getString(4));
                tb4.setText(rs.getString(5));
                tb5.setText(rs.getString(6));
                tb6.setText(rs.getString(7));
                gioitinh=rs.getBoolean(3);
                stranh=rs.getString(9);
                manv=tb1.getText();
                System.out.println(manv);
            }
            if(gioitinh==true)
            {
                rb3.setSelected(gioitinh);
            }
            
            if(gioitinh==false)
            {
                rb4.setSelected(gioitinh);
            }
            if(kiemtra>0)
            {
                
            hien();
            panh1.removeAll();
            if(stranh!=null)
            {
                System.out.println(stranh);
                        file = new File(stranh);
                        bufImg=ImageIO.read(file);
                        paint1 b = new paint1(bufImg);
                        
                        b.setSize(200, 200);
                        b.setLocation(0, 0);
                        b.setVisible(true);
                        b.setBorder(BorderFactory.createLineBorder(Color.red));
                        panh1.add(b);
                        panh1.updateUI();
                        panh1.setVisible(true);
            }
            }
            if(stranh==null)
            {
                stranh="D:\\Anh\\1.jpg";
                file = new File(stranh);
                        bufImg=ImageIO.read(file);
                        paint1 b = new paint1(bufImg);
                        
                        b.setSize(200, 200);
                        b.setLocation(0, 0);
                        b.setVisible(true);
                        b.setBorder(BorderFactory.createLineBorder(Color.red));
                        panh1.add(b);
                        panh1.updateUI();
                        panh1.setVisible(true);
            }
            if(kiemtra==0)
            {
                JOptionPane.showMessageDialog(this, "Mã nhân viên không tồn tại vui lòng kiểm tra lại.");
            }
        } catch (IOException ex) {
            Logger.getLogger(UpdateNV.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(UpdateNV.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }//GEN-LAST:event_jButton4ActionPerformed

    private void cb1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cb1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cb1ActionPerformed
    public void an()
    {
        l1.setVisible(false);
        l2.setVisible(false);
        l3.setVisible(false);
        l4.setVisible(false);
        l5.setVisible(false);
        l6.setVisible(false);
        l7.setVisible(false);
        l9.setVisible(false);
        tb2.setVisible(false);
        tb3.setVisible(false);
        tb4.setVisible(false);
        tb5.setVisible(false);
        tb6.setVisible(false);
        b1.setVisible(false);
        b2.setVisible(false);
        b3.setVisible(false);
        rb3.setVisible(false);
        rb4.setVisible(false);
        cb1.setVisible(false);
        panh1.setVisible(false);
    }
    public void hien()
    {
        panh1.setVisible(true);
        cb1.setVisible(true);
        l1.setVisible(true);
        l2.setVisible(true);
        l3.setVisible(true);
        l4.setVisible(true);
        l5.setVisible(true);
        l6.setVisible(true);
        l7.setVisible(true);
        l9.setVisible(true);
        tb2.setVisible(true);
        tb3.setVisible(true);
        tb4.setVisible(true);
        tb5.setVisible(true);
        tb6.setVisible(true);
        b1.setVisible(true);
        b2.setVisible(true);
        b3.setVisible(true);
        rb3.setVisible(true);
        rb4.setVisible(true);
    }
    public void loadData(String str)
    {
        try {
            Ketnoi a = new Ketnoi();
            Connection con = a.connect();
            PreparedStatement pst = con.prepareCall("Select * from nhanvien where manv = ?");
            pst.setString(1, str);
            ResultSet rs = pst.executeQuery();
            while(rs.next())
            {
                if(rs.getBoolean(3)==true)
                {
                    jrb1.setSelected(true);
                }
                if(rs.getBoolean(3)==false)
                {
                    jrb2.setSelected(true);
                }
                jtb2.setText(rs.getString(7));
                jtb3.setText(rs.getString(5));
                jtb4.setText(rs.getString(4));
                String st=rs.getString(8);
                PreparedStatement pst1 = con.prepareCall("Select * from bophan where mabp = ?");
                pst1.setString(1, st);
                ResultSet rs1 = pst1.executeQuery();
                while(rs1.next())
                {
                    jtb1.setText(rs1.getString(2));
                }
                if(rs.getString(9)!=null)
                {
                loadAnh(jp3,rs.getString(9));
                }
                if(rs.getString(9)==null)
                {
                loadAnh(jp3,"D:\\Anh\\1.jpg");
                }
            }
        } catch (SQLException ex) {
            Logger.getLogger(UpdateNV.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton b1;
    private javax.swing.JButton b2;
    private javax.swing.JButton b3;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.JComboBox cb1;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JPanel jp3;
    private javax.swing.JRadioButton jrb1;
    private javax.swing.JRadioButton jrb2;
    private javax.swing.JTable jt1;
    private javax.swing.JTextField jtb1;
    private javax.swing.JTextField jtb2;
    private javax.swing.JTextField jtb3;
    private javax.swing.JTextField jtb4;
    private javax.swing.JLabel l1;
    private javax.swing.JLabel l2;
    private javax.swing.JLabel l3;
    private javax.swing.JLabel l4;
    private javax.swing.JLabel l5;
    private javax.swing.JLabel l6;
    private javax.swing.JLabel l7;
    private javax.swing.JLabel l9;
    private javax.swing.JPanel panh;
    private javax.swing.JPanel panh1;
    private javax.swing.JRadioButton rb1;
    private javax.swing.JRadioButton rb2;
    private javax.swing.JRadioButton rb3;
    private javax.swing.JRadioButton rb4;
    private javax.swing.JTextField t1;
    private javax.swing.JTextField t2;
    private javax.swing.JTextField t3;
    private javax.swing.JTextField t4;
    private javax.swing.JTextField t5;
    private javax.swing.JTextField t6;
    private javax.swing.JTextField tb1;
    private javax.swing.JTextField tb2;
    private javax.swing.JTextField tb3;
    private javax.swing.JTextField tb4;
    private javax.swing.JTextField tb5;
    private javax.swing.JTextField tb6;
    // End of variables declaration//GEN-END:variables



    @Override
    public void valueChanged(ListSelectionEvent e) {
        int num=jt1.getSelectedRow();
        String str = jt1.getValueAt(num, 0).toString();
        System.out.println(str);
        if(num>=0)
        {
            loadData(str);
        }
    }

    @Override
    public void keyTyped(KeyEvent e) {
        
    }

    @Override
    public void keyPressed(KeyEvent e) {
        if(e.getKeyCode()==KeyEvent.VK_ENTER)
        {
            timkiem();
        }
    }

    @Override
    public void keyReleased(KeyEvent e) {
        
    }


}
